<!doctype html>
<html>
  <head>
    <title>Notifications: ServiceWorkerRegistration.getNotifications() with a notification replacement.</title>
    <script src="../resources/testharness.js"></script>
    <script src="../resources/testharnessreport.js"></script>
    <script src="../serviceworker/resources/test-helpers.js"></script>
    <script src="resources/test-helpers.js"></script>
  </head>
  <body>
    <script>
      // Tests that the getNotifications() function when used in a document returns
      // an array of the notifications which were previously displayed using a filter.
      // Notifications replaced using the `tag` should not be included anymore.
      async_test(function(test) {
          var scope = 'resources/scope/' + location.pathname,
              script = 'instrumentation-service-worker.js';

          testRunner.setPermission('notifications', 'granted', location.origin, location.origin);

          var registration = null;
          getActiveServiceWorkerWithMessagePort(test, script, scope).then(function(workerInfo) {
              registration = workerInfo.registration;

              return registration.showNotification('Hello, world!', {
                body: 'First notification',
                tag: 'banana',
              });
          }).then(function() {
              return registration.showNotification('Hello again, world!', {
                body: 'Second notification',
                tag: 'banana',
              });
          }).then(function() {
            return registration.getNotifications({ tag: 'banana' });
          }).then(function(notifications) {
              assert_equals(notifications.length, 1);

              assert_equals(notifications[0].title, 'Hello again, world!');
              assert_equals(notifications[0].body, 'Second notification');

              test.done();
          }).catch(unreached_rejection(test));

      }, 'ServiceWorkerRegistration.getNotifications() does not return replaced notifications.');
    </script>
  </body>
</html>
